<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
</head>
<body>
<t:formvalid formid="formobjService" dialog="false" usePlugin="password" layout="table" action="" tiptype="tipType"
             validFormName="formValidName" showAllError="true">
    <input type="hidden" value="${serviceId}" name="serviceId" id="serviceId">
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="15%">
                <label>邮箱:</label>
            </td>
            <td width="70%">
                <input class="inputxt" id="phone" name="phone" value="" datatype="e" nullMsg="请输入邮箱"
                       errorMsg="邮箱格式不正确"/>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="15%" valign="top">
                <label>邮件内容:</label>
            </td>
            <td width="70%">
                <textarea style="width: 300px; height: 174px; margin: 0px;" name="htmlText" id="htmlText"
                          datatype="*0-500" nullMag="邮件内容不能为为空"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <a href="#" class="easyui-linkbutton l-btn" id="submitBtn2">确认发送</a>
                <a href="#" class="easyui-linkbutton l-btn" id="cancelPlan2" onclick="cancelPlanButton()">取消</a>
            </td>
        </tr>
        </tbody>
    </table>
</t:formvalid>
</body>
<script>

    var form;
    $(function () {
        form = $("#formobjService").Validform({
            ignoreHidden: true,
            postonce: true,
            showAllError: true,
            ajaxPost: true,
            tiptype: 3,
        });
        $("#submitBtn2").click(function () {
            save();
        });
    });


    function save() {
        //调用formValidata 进行验证，并能阻止提交
        if (!form.check(false)) {
            form.submitForm(false);
        }
        var phone = $("#phone").val();
        var html = $("#htmlText").val();
        if ("" == phone) {
            tip("邮箱不能为空");
            return false;
        }
        if ("" == html) {
            tip("邮件内容不能为空");
            return false;

        } else {
            $.ajax({
                url: "cbsServiceController.do?saveServiceAndEmail",
                data: {
                    "serviceId": $("#serviceId").val(),
                    "phone": phone,
                    "htmlText": html
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                success: function (data) {
                    if (data.success) {
                        var serviceId = $("#serviceId").val();
                        console.info("serviceId==" + serviceId);
                        //提示
                        top.tip(data.msg);
                        frameElement.api.close();
                    }
                }
            });
        }
    }

    function cancelPlanButton() {
//        closetab('新建服务单');
        frameElement.api.close();
    }
</script>
</html>
